package pat;

import java.util.Scanner;
import java.lang.String;

public class B1014 {

    public static void print(char[] chars, int x) {
        int o1 = chars[0] - 64;

        switch (o1) {
            case 1:
                System.out.print("MON ");
                break;
            case 2:
                System.out.print("TUE ");
                break;
            case 3:
                System.out.print("WED ");
                break;
            case 4:
                System.out.print("THU ");
                break;
            case 5:
                System.out.print("FRI ");
                break;
            case 6:
                System.out.print("SAT ");
                break;
            case 7:
                System.out.print("SUN ");
                break;
        }

        if (chars[1] <= '9') {
            int o2 = chars[1] - 48;
            System.out.print("0" + o2 + ":");
        } else if (chars[1] >= 'A') {
            int o2 = chars[1] - 55;
            System.out.print(o2 + ":");
        }

        if (x <= 9) {
            System.out.print("0" + x);
        } else {
            System.out.print(x);
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        String strs[] = new String[4];
        char chars[] = new char[2];
        int int3 = 0;
        int index = 0;
        String output = "";

        for (int i = 0; i < 4; i++) {
            strs[i] = input.next();
        }

        for (int i = 0; i < Math.min(strs[0].length(), strs[1].length()); i++) {
            char ch0 = strs[0].charAt(i);
            char ch1 = strs[1].charAt(i);
            if ((ch0 == ch1) && (('A' <= ch0) && (ch0 <= 'G'))) { // !大写字母是A-G不是A-Z
                chars[0] = ch0;
                index = i;
                break;
            }
        }

        for (int i = index + 1; i < Math.min(strs[0].length(), strs[1].length()); i++) {
            char ch0 = strs[0].charAt(i);
            char ch1 = strs[1].charAt(i);
            if ((ch0 == ch1) && ((('A' <= ch0) && (ch0 <= 'N')) || (('0' <= ch0) && (ch0 <= '9')))) { //小时的话是从（1）后面的来算第一个0-9或者A-N,不是A-Z
                chars[1] = ch0;
                break;
            }
        }

        for (int i = 0; i < Math.min(strs[2].length(), strs[3].length()); i++) {
            char ch0 = strs[2].charAt(i);
            char ch1 = strs[3].charAt(i);
            if ((ch0 == ch1) && ((('a' <= ch0) && (ch0 <= 'z')) || ((ch0 >= 'A') && (ch0 <= 'Z')))) {
//            if ((ch0 == ch1) && (('a' <= ch0) && (ch0 <= 'z'))) {
                int3 = i;
                break;
            }
        }

        print(chars, int3);
    }
}
